<?php
require_once '../config/config.php';
require_once '../class/dbclass.php';
require_once '../class/User.php';

$user = new User();
$dbcn = new MySQLCN();

if($_POST['type']=='login'){
	if($user->login()){
	
	       $user_id=$_SESSION['SESS_MEMBER_ID'];
		   
			$results = $dbcn->select("SELECT * FROM menu,link where menu.parent=0 and link.mid=menu.mid and link.user_id='$user_id' order by menu.rank");  
			
			//$rows = mysql_fetch_array($results, MYSQL_BOTH);
			//$mid=$rows['mid'];
			$mid=$results[0]['mid'];
				
			//$img_path="background-image: url(".$rows['img_path'].")";
			$title=$results[0]['title'];
			$m_id1=$_GET['mid'];
			
			$sql1="select * from menu,link where menu.mid=link.mid and link.user_id='$user_id' and menu.parent='$mid' and menu.rank=1";	
			
			$result_page = $dbcn->select($sql1);
			$numb = $dbcn->chknum($sql1);
			
			//$numb=mysql_num_rows($result_page);
			
				if($numb==0)
				{
					$path="$results[0][path]&mid=".$mid;
				}
				else
				{
					//$row_page=mysql_fetch_array($result_page);
					$mid1=$result_page[0]['mid'];
					$path1=$result_page[0]['path'];
					
					$sql2 = "select * from menu,link where menu.mid=link.mid and link.user_id='$user_id' and menu.parent='$mid1' and menu.rank=1";
					$result_page1 = $dbcn->select($sql2);
					
					//$numb1=mysql_num_rows($result_page1);
					$numb1 = $dbcn->chknum($sql2);
					
					//$row_page1=mysql_fetch_array($result_page1);
					$path2=$result_page1[0]['path'];
					$smid=$result_page1[0]['mid'];
					
					if($numb1>0)
					{
					$path="$path2&mid=".$mid."&smid=".$smid;
					}
					else
					{
					$path="$path1&mid=".$mid."&smid=".$mid1;
					}
				}
			

			header("location: ../$path");

	//header('Location: ../index.php');
	}else{
		$_SESSION['Msg'] = "Inavalid UserName Or Password";
		header('Location: ../index.html');
	}
}
?>